package homework.test2;

import java.util.ArrayList;
import java.util.Iterator;

/*
//使用ArrayList 对象存储字符串并遍历 三种方式
 */
public class Demo2 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");

        //循环遍历
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.println(s);
        }

        System.out.println("-----------------------");

        //迭代器遍历
        Iterator<String> it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("-----------------------");

        //增强for
        for (String s : list) {
            System.out.println(s);
        }
    }
}
